package com.example.test_event_and_callback.infras.async;

import com.example.test_event_and_callback.impl.TestAsyncDto;
import lombok.SneakyThrows;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

public class DemanderProcessorMethodHandle extends AsyncDemanderProcessor<MethodHandle> {

    public DemanderProcessorMethodHandle(Class<?> demanderClass) {
        init(demanderClass);
    }

    @Override
    MethodHandle exchangeMethod(Field field, Method method) {
        return MethodExchange.toMethodHandle(method);
    }



    @Override
    <T extends Demander> void setParam(T dto, String paramName, Object param) throws Throwable {
        mappedMethods.get(paramName).invoke(((AsyncDemanderProxy)dto).getInstance(), param);
    }


}
